/*!
 * \file Generator.h
 * \brief Base class for all generators
 */

#ifndef GENERATOR_H
#define GENERATOR_H

#include "GeneratorEnvironment.h"
#include "StateBase.h"
#include <deque>

namespace tsc
{
namespace common
{

/**
 * Base class for all generators
 */
class Generator
{
public:
	/**
	 * Returns ID of the generator
	 * \return id of generator
	 */
	int getGeneratorId() const;

	/**
	 * Sets the new ID of the generator
	 * \param generatorId new value of ID
	 */
	void setGeneratorId(int generatorId);

	/**
	 * Gets current state of this generator
	 * \return pointer to current state of generator
	 */
	StateBase* getCurrentState() const;

	/**
	 * Changes generator state
	 * If the current state and the new one are the same then
	 * this call has no effect.
	 *
	 * \param newState new state for this generator
	 */
	void changeState(StateBase* newState);

	/**
	 * Handle specified event for the specified generator.
	 * This method calls the handleEvent method for the current state of
	 * generator to actually handle the event.
	 *
	 * \param event the event to handle
	 */
	void injectEvent(EventData*& event);

	void removeGenerator();

	virtual ~Generator();

protected:
	Generator(GeneratorEnvironment& ge,
			  StateBase* pInitialState);

private:
	void eventLoop();

protected:
	int _generatorId;

	StateBase* _currentState;

	std::deque<EventData*> _eventQueue;
	bool _isRunning;

	GeneratorEnvironment& _ge;
	bool _isRemoved;
};

} // namespace common
} // namespace tsc

#endif // GENERATOR_H
